package com.example.tests;


import static com.example.fw.ContactHelper.CREATION;
import static com.example.tests.ContactDataGenerator.loadContactsFromXmlFile;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.example.data.ContactData;
import com.example.utils.SortedListOf;

public class ContactCreationTests extends TestBase {
	
	@DataProvider
	public Iterator<Object[]> contactFromFile() throws IOException{
		return wrapDataForDataProvider(loadContactsFromXmlFile(new File("contacts.xml"))).iterator();
	}
	

	@Test(dataProvider = "contactFromFile")
	  public void testCreationWithValidData(ContactData contact) throws Exception {	    
		SortedListOf<ContactData> oldList = app.getContactHelper().getContacts();	    	    
	    app.getContactHelper().createContact(contact, CREATION);	 
	    SortedListOf<ContactData> newList = app.getContactHelper().getContacts();		   
	    assertThat(newList, equalTo(oldList.withAdded(contact)));
	  }

	
      
}
